package com.yanqu.road.server.manger.union.listener;

import com.yanqu.road.entity.enums.eUnionSyncType;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.manger.ICrossUnionSyncListener;
import com.yanqu.road.server.manger.beautyescort.BeautyEscortMgr;

import java.util.ArrayList;
import java.util.List;

/**
 * 美女走镖系统监听
 */
public class BeautyEscortListener implements ICrossUnionSyncListener {

    @Override
    public void notifySync(int syncType, long playerId, CrossUnionInfo unionInfo, List<CrossUnionMember> memberList) {


        List<Long> userList = new ArrayList<>();

        for (CrossUnionMember member : memberList) {
            //过滤其他区服玩家
            if(member.getServerId() != GameServer.getInstance().getServerId()){
                continue;
            }
            userList.add(member.getUserId());

            if(syncType == eUnionSyncType.CreateUnion.getValue()){
                BeautyEscortMgr.createUnion(unionInfo, member.getUserId());
            }else if(syncType == eUnionSyncType.QuitUnion.getValue()){
                BeautyEscortMgr.quitUnion(member.getUserId(), unionInfo);
            }else if(syncType == eUnionSyncType.DeleteUnion.getValue()){

            }else if(syncType == eUnionSyncType.JoinUnion.getValue()){
                BeautyEscortMgr.unionMemberJoin(unionInfo, member.getUserId());
            }else if(syncType == eUnionSyncType.BeKick.getValue()){
                BeautyEscortMgr.kickPlayer(unionInfo, member.getUserId());
            }
        }

        if(syncType == eUnionSyncType.DeleteUnion.getValue()){
            BeautyEscortMgr.deleteUnion(userList, unionInfo);
        }

    }
}
